package com.bestcem.xm.ticket.dao.mapper;

import com.bestcem.xm.ticket.entity.mongo.ExportTicketParamDO;
import com.bestcem.xm.ticket.entity.mysql.TicketDO;
import com.bestcem.xm.ticket.service.dto.DatetimeFilter;
import com.bestcem.xm.ticket.service.dto.RegionFilter;
import com.bestcem.xm.ticket.service.dto.dashboard.DateTypeCountDTO;
import com.bestcem.xm.ticket.service.dto.dashboard.StatusCountDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author zhangfeng <feng.zhang@idiaoyan.com>
 * @version v1.0
 * @date 2021/9/24 11:38
 */
@Mapper
public interface TicketDaoMapper {

    List<StatusCountDTO> countByStatus(@Param("regionFilter") RegionFilter regionFilter,
                                       @Param("datetimeFilter") DatetimeFilter datetimeFilter);

    Long countHasFollowOverdue(@Param("regionFilter") RegionFilter regionFilter,
                               @Param("datetimeFilter") DatetimeFilter datetimeFilter);

    Long countHasAuditOverdue(@Param("regionFilter") RegionFilter regionFilter,
                              @Param("datetimeFilter") DatetimeFilter datetimeFilter);

    List<DateTypeCountDTO> countByDate(@Param("regionFilter") RegionFilter regionFilter,
                                       @Param("startTime") LocalDateTime startTime,
                                       @Param("endTime") LocalDateTime endTime);

    TicketDO findByTicketId(String ticketId);

    void insert(TicketDO ticketDO);

    void updateByTicketId(TicketDO ticketDO);

    List<TicketDO> listBySurveyId(String surveyId);

    long countBySurveyId(String surveyId);

    TicketDO findByOrgIdAndCurFollowUserIdAndStatusAndTicketId(String orgId, String curFollowUserId,
                                                               Integer status, String ticketId);

    TicketDO findByOrgIdAndCurFollowUserIdAndStatus(String orgId, String curFollowUserId, Integer status);

    List<TicketDO> listByResId(Integer resId);

    Long countByExportTicketParam(ExportTicketParamDO param);

    List<TicketDO> listByExportTicketParam(ExportTicketParamDO param);

    /**
     * 查询所有页面上可显示的工单记录
     *
     * @param configId 行动规则id
     * @return
     */
    List<TicketDO> listUsableByConfigId(String configId);

    /**
     * 更新工单日志id
     *
     * @param ticketId        工单id
     * @param ticketRecordIds 工单日志id string的json数组
     */
    void updateTicketRecordId(String ticketId, String ticketRecordIds);

    List<Long> listResIdByOrgId(String orgId);
}
